#pragma once
#include <DataStorageBase.h>
#include <mail.h>
#include <module_header_reg.h>
#include "module_general_reg.h"

#define DATA_STORAGE_HEADER_REG_SIZE 40


#define DATA_STORAGE_STATUS_EOF_ADDRESS   (int)(sizeof(module_general_reg_t)+DATA_STORAGE_HEADER_REG_SIZE)



class DataStorageIO : public DataStorageBase
{
public:
    DataStorageIO(Mail<>& mb);
    
    void make_default() override;

    bool load() override;

    int read_data_storage_eof() override;
    
    void check_update() override;

    module_header_reg_t& module_header_reg() override
    {
        return DataStorageIO::module_reg().module_header_reg;
    }

    data_storage_reg_read_t& get_reg_data(uint8_t reg_address) override;
    
    
    static module_reg_t& module_reg()
    {
        static module_reg_t module_reg;
        return module_reg;
    }

protected:

    constexpr uint32_t data_storage_header_size()
    {
        return sizeof(module_header_reg_t);
    }
    constexpr uint32_t data_storage_general_size()
    {
        return sizeof(module_general_reg_t);
    }

private:
    //数据存储的头部
    data_storage_eof_t _data_storage_eof;
    data_storage_reg_read_t _reg_read;
    Mail<>& _mb;
};

